/*!
	\file    main.c
	\brief   led spark with systick, USART print and key example

	\version 2024-01-05, V2.3.0, firmware for GD32F10x
*/

/*
	Copyright (c) 2024, GigaDevice Semiconductor Inc.

	Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice, this
	   list of conditions and the following disclaimer.
	2. Redistributions in binary form must reproduce the above copyright notice,
	   this list of conditions and the following disclaimer in the documentation
	   and/or other materials provided with the distribution.
	3. Neither the name of the copyright holder nor the names of its contributors
	   may be used to endorse or promote products derived from this software without
	   specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/

#include "gd32f10x.h"
#include "systick.h"
#include <stdio.h>
#include "main.h"
#include "board.h"

#include "dac.h"

// Tips//
/*
1.Flickering is normal when EPD is performing a full screen update to clear ghosting from the previous image so to ensure better clarity and legibility for the new image.
2.There will be no flicker when EPD performs a partial update.
3.Please make sue that EPD enters sleep mode when update is completed and always leave the sleep mode command. Otherwise, this may result in a reduced lifespan of EPD.
4.Please refrain from inserting EPD to the FPC socket or unplugging it when the MCU is being powered to prevent potential damage.)
5.Re-initialization is required for every full screen update.
6.When porting the program, set the BUSY pin to input mode and other pins to output mode.
*/

int main(void)
{
	/* configure systick */
	systick_config();
	gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP, ENABLE);
	/* initilize the LEDs, USART and key */
	board_led_init();
	board_button_init();
	board_usart0_init();
	board_can_init();
	/* print out the clock frequency of system, AHB, APB1 and APB2 */
	printf("CHENXI Studio Core Board TEST\r\n");
	printf("CK_SYS is %d\r\n", rcu_clock_freq_get(CK_SYS));
	printf("CK_AHB is %d\r\n", rcu_clock_freq_get(CK_AHB));
	printf("CK_APB1 is %d\r\n", rcu_clock_freq_get(CK_APB1));
	printf("CK_APB2 is %d\r\n", rcu_clock_freq_get(CK_APB2));
	printf("\r\nBoard GET ID \r\n");
	uint32_t CpuID[3];
	CpuID[0] = *(__IO uint32_t *)(0x1FFFF7E8 + 8);
	CpuID[1] = *(__IO uint32_t *)(0x1FFFF7E8 + 4);
	CpuID[2] = *(__IO uint32_t *)(0x1FFFF7E8);
	printf("###########CPU ID:%X-%X-%X\r\n", CpuID[0], CpuID[1], CpuID[2]);
	uint32_t canID = CpuID[2] & 0x1FFFFFFF;

    dac_config();
	while (1)
	{

	}
}
